var parkOrgparJs = function(targetObj){
	this.sysUtils = new kendoUtils();
	this.targetObj = targetObj;
	this.init();
	return this;
};


var chargeBinfo = function(id, $list) {
	if (id == undefined || !id) {
		this.id = "d-" + new Date().getTime();
	} else {
		this.id = id;
	}
	this.$list = $list;
	return this;
}
chargeBinfo.prototype = {
		addToList : function($p) {
			$p.createTr(this.$list.find("tbody"));
		}
}
parkOrgparJs.prototype={
		init:function(){
			var bindFieldArray = this.sysUtils.getBindFieldArray(this.targetObj);
			var bindFunctionArray = [
			                         {fName:"saveparOrg",fs:this.saveparOrg},
			                         {fName:"createRow",fs:this.createRow},
			                         {fName:"cancel",fs:parkTree.resetTree},
			                         {fName:"deleteRow",fs:this.deleteRow}];
			this.bindBaseModels = new bindBaseModel(null,bindFieldArray,bindFunctionArray,null);
			this.sysUtils.bindDoucment(this.bindBaseModels,this.targetObj,this);
			this.loadParinfo();
//			this.showOff();
		},
		loadParinfo:function (e) {
			var that = this;
			that.editResult = null;
			that.isEdit = null;
			if (!isEmpty(e)) {
				that = $(e.target).data("that");
			}
			var id = zTree.getSelectedNodes()[0].id,level=zTree.getSelectedNodes()[0].level;
			var url = baseApiPath+"facilities/parkInfo";
			if(id){
				that.isEdit = true;
				url += '?isEdit='+that.isEdit+'&organizationCode='+id;
			}else{
				that.isEdit = false;
				var node = zTree.getSelectedNodes()[0].getParentNode();
				url = baseApiPath+'facilities/addOrz?isEdit='+that.isEdit+'&pid='+node.id+'&lev='+level+'&gpc=par';
			}
			JsonpAjax(url,null,"json",function(result){
				that.editResult = result;
				that.sysUtils.setVariantBindFieldValue(result);
				that.targetObj.find("oid").val(result.organizationCode);
				that.setswitchCss();
			},false);
			JsonpAjax(baseApiPath+"chargeStandard/chargeOptions?chargeType=1",null,"json",function(result){
				that.tempchargeList = result;
			},false);
			JsonpAjax(baseApiPath+"chargeStandard/chargeOptions?chargeType=0",null,"json",function(result){
				that.monthchargeList = result;
			},false);


			if(null == that.editResult){
				var charge_list = that.targetObj.find("#charge_list > tbody");
				$(Utils.getModelArrayByParentModelKey(BASIS.VEHICLE_TYPE.ROOT)).each(function(index){
					that.createTr(charge_list,index,null,this.modelKey);
				});
				return; //新增啥都不需要做
			}
			var arrayinfo = isEmpty(that.editResult.equipmentManagements.charge)?null:isEmpty(that.editResult.equipmentManagements.charge.chargelist)?null:that.editResult.equipmentManagements.charge.chargelist;
			var map = new Map();

			if(!isEmpty(arrayinfo)){
				for (var i = 0,l=Object.getOwnPropertyNames(arrayinfo).length; i < l; i++) {
					var key = "charge"+i;
					if(arrayinfo.hasOwnProperty(key)){
						var item = eval('(' + arrayinfo[key] + ')');
						map.put(item["carType"], item);
					}
				}
			}
			var charge_list = that.targetObj.find("#charge_list > tbody");
			$(Utils.getModelArrayByParentModelKey(BASIS.VEHICLE_TYPE.ROOT)).each(function(index){
				that.createTr(charge_list,index,map.get(this.modelValue),this.modelKey);
			});
//			if(charges){
//			var l = Object.getOwnPropertyNames(charges).length;
//			if (charges && l < 1) {
//			return;
//			}
//			for (var i = 0; i < l; i++) {
//			var key = "charge"+i;
//			if(charges.hasOwnProperty(key)){
//			var item = eval('(' + charges[key] + ')');
//			that.createTr(that.targetObj.find("#charge_list > tbody"),i,item);
//			}

//			}
//			}


			/*var equments = that.editResult.equipmentManagements;
			if(null != equments.charge){
				if(!isEmpty(equments.charge["ckRepeatIE"])){
                    var editCkRepeatIE = equments.charge["ckRepeatIE"].split(",");
                    repeatOutIn.find("input").each(function(){
                        for(var i = 0;i<editCkRepeatIE.length;i++){
                            if($(this).data("modelValue") == editCkRepeatIE[i]){
                                this.checked = true;
                            }
                        }
                    });
                }
                if(!isEmpty(equments.charge["ckIE"])){
                    var editCkIE = equments.charge["ckIE"].split(",");
                    outIn.find("input").each(function(){
                        for(var i = 0;i<editCkIE.length;i++){
                            if($(this).data("modelValue") == editCkIE[i]){
                                this.checked = true;
                            }
                        }
                    });

                }
                if(!isEmpty(equments.charge["fullStopIn"])){
                    var editCkfullStopIn = equments.charge["fullStopIn"].split(",");
                    fullStopIn.find("input").each(function(){
                        for(var i = 0;i<editCkfullStopIn.length;i++){
                            if($(this).data("modelValue") == editCkfullStopIn[i]){
                                this.checked = true;
                            }
                        }
                    });
                }
			}*/
			var dictcarTypes = Utils.getModelArrayByParentModelKey(BASIS.CAR_TYPE.ROOT);
			var carTypes = that.editResult.equipmentManagements.carTypes;
			var n = Object.getOwnPropertyNames(dictcarTypes).length - 1;
			if(carTypes){
				if (carTypes && n < 1) {
					return;
				}

				for (var i = 0; i < n; i++) {
					var key = "cartype"+i;
					if(carTypes.hasOwnProperty(key)){
						var item = eval('(' + carTypes[key] + ')');
						that.createTr2(that.targetObj.find("#carType_list > tbody"),i,item,dictcarTypes);
					}else{
						that.createTr2(that.targetObj.find("#carType_list > tbody"),i,null,dictcarTypes);
					}
				}
			}else{
				for (var i = 0; i < n; i++) {
					that.createTr2(that.targetObj.find("#carType_list > tbody"),i,null,dictcarTypes);
				}
			}

            //通道进出设置

           /* var carType = Utils.getModelArrayByParentModelKey(BASIS.TRAFFIC_TYPE_CLASS.ROOT);
            var repeatOutIn = this.targetObj.find("#repeatOutIn");
            $(carType).each(function(){
                var html = $("<input type='checkbox' name='ckRepeatIE' onchange='parOrg.selectOutIN("+this.modelValue+")' data-index='"+this.modelValue+"' style='margin-left: 20px'/><span>" + this.modelName + "</span>");
                $(html[0]).data("modelValue",this.modelValue);
                repeatOutIn.append(html);
            });
            var outIn = this.targetObj.find("#outIn");
            $(carType).each(function(){
                var html = $("<input type='checkbox' name='ckIE' onchange='parOrg.selectReaptOutIN("+this.modelValue+")' data-index='"+this.modelValue+"' style='margin-left: 20px'/><span>" + this.modelName + "</span>");
                $(html[0]).data("modelValue",this.modelValue);
                outIn.append(html);
            });
            var fullStopIn = this.targetObj.find("#fullStopIn");
            $(carType).each(function(){
                var html = $("<input type='checkbox' name='ckfullStopIn'  data-index='"+this.modelValue+"' style='margin-left: 20px'/><span>" + this.modelName + "</span>");
                $(html[0]).data("modelValue",this.modelValue);
                fullStopIn.append(html);
            });*/
            var accessCtrl = !isEmpty(that.editResult.accessCtrl)?that.editResult.accessCtrl:null;

            if(!isEmpty(accessCtrl)){
                var access_list = that.targetObj.find("#access_list > tbody");
                for (var i = 0,l=accessCtrl.length; i < l; i++) {
                    that.createTr3(access_list,i,accessCtrl[i]);
                }
            }

			parkTree.hideMask();
		},
		setswitchCss:function () {
			var that = this;
			that.targetObj.find(".checkbox input[type='checkbox']").each(function () {
				$(this).click(function(){
					this.value= this.value !=1 ? 1 : 0;
					if(this.id == 'calflag'){
//						that.showOff();
						var calcheck = that.targetObj.find('#calflag').val() == 'on' ? false : that.targetObj.find('#calflag').val() == 0 ? false : true;
						that.selectDisable(calcheck);
					}
				});
				if(this.value == 1){
					this.checked=true;
				}else{
					this.value=0;
					this.checked=false;
				}
                var bindS = $(this).attr('data-bind');
                that.sysUtils.mvvmModel.set(bindS.substr(bindS.indexOf(':')+1,bindS.length),this.value);
			});
		},
		selectOutIN:function (id) {
            var that = this;
            that.targetObj.find('input[name="ckRepeatIE"]').each(function () {
            	if(this.checked && id == this.getAttribute("data-index")){
                    that.targetObj.find('input[name="ckIE"]').each(function () {
                        if(id == this.getAttribute("data-index")){
                            this.checked=true;
                        }
                    });
				}
            });
		},
    	selectReaptOutIN:function (id) {
			var that = this;
			that.targetObj.find('input[name="ckIE"]').each(function () {
				if(!this.checked && id == this.getAttribute("data-index")){
					that.targetObj.find('input[name="ckRepeatIE"]').each(function () {
						if(id == this.getAttribute("data-index")){
							this.checked=false;
						}
					});
				}
			});
		},
		showOff:function () {
			layer.closeAll();
			var that = this;
			var calcheck = that.targetObj.find('#calflag').val() == 'on' ? false : that.targetObj.find('#calflag').val() == 0 ? false : true;
//			var difcheck = that.targetObj.find('#difflag').val() == 'on' ? false : that.targetObj.find('#difflag').val() == 0 ? false : true;
			if(calcheck){//
				that.targetObj.find('#one').hide();
				that.targetObj.find('#two').hide();
				that.targetObj.find('#workingDaysStandard').prop('required',false);
				that.targetObj.find('#holidaySeasonStandard').prop('required',false);
				that.targetObj.find('#three').show();
			}else if(!calcheck){//
				that.targetObj.find('#workingDaysStandard').prop('required',false);
				that.targetObj.find('#holidaySeasonStandard').prop('required',false);
				that.targetObj.find('#one').hide();
				that.targetObj.find('#two').hide();
				that.targetObj.find('#three').show();
			}else if(calcheck && !difcheck){
				that.targetObj.find('#workingDaysStandard').prop('required',true);
				that.targetObj.find('#holidaySeasonStandard').prop('required',true);
				that.targetObj.find('#one').show();
				that.targetObj.find('#two').show();
				that.targetObj.find('#three').hide();
			}else{
				that.targetObj.find('#workingDaysStandard').prop('required',true);
				that.targetObj.find('#holidaySeasonStandard').prop('required',false);
				that.targetObj.find('#one').show();
				that.targetObj.find('#two').hide();
				that.targetObj.find('#three').hide();
			}
		},
		selectDisable:function (calcheck) {
			var $this = this;
			this.targetObj.find("#charge_list tbody tr").each(function(){
				if(calcheck){
					$(this).find('td').eq(1).hide();
					$(this).find('td').eq(2).show();
					$(this).find('td').eq(3).show();
					$(this).find('td').eq(1)[0].children[0].required =false;
					$(this).find('td').eq(4)[0].children[0].required =false;
					$(this).find('td').eq(2)[0].children[0].required =true;
					$(this).find('td').eq(3)[0].children[0].required =true;
//					$this.targetObj.find('thead tr th:eq(2)').hide();
//					$this.targetObj.find('thead tr th:eq(3)').show();
//					$this.targetObj.find('thead tr th:eq(4)').show();
				}else if(!calcheck) {
					$(this).find('td').eq(1).show()
					$(this).find('td').eq(2).hide();
					$(this).find('td').eq(3).hide();
					$(this).find('td').eq(1)[0].children[0].required =true;
					$(this).find('td').eq(4)[0].children[0].required =true;
					$(this).find('td').eq(2)[0].children[0].required =false;
					$(this).find('td').eq(3)[0].children[0].required =false;
//					$this.targetObj.find('thead tr th:eq(2)').show();
//					$this.targetObj.find('thead tr th:eq(3)').hide();
//					$this.targetObj.find('thead tr th:eq(4)').hide();
				}
//				else{
//				$(this).find('td').eq(1)[0].children[0].required =false;
//				$(this).find('td').eq(2)[0].children[0].required =false;
//				$(this).find('td').eq(3)[0].children[0].required =false;
//				$(this).find('td').eq(4)[0].children[0].required =false;
//				}
			});
			if(calcheck){
				$this.targetObj.find('thead tr th:eq(1)').hide();
				$this.targetObj.find('thead tr th:eq(2)').show();
				$this.targetObj.find('thead tr th:eq(3)').show();
			}else if(!calcheck) {
				$this.targetObj.find('thead tr th:eq(1)').show();
				$this.targetObj.find('thead tr th:eq(2)').hide();
				$this.targetObj.find('thead tr th:eq(3)').hide();
			}
		},
		changeColor:function (obj) {
			var id =obj.id;
			$('#pager a').each(function(){
				if(id=='5'){
					if(this.id =='5'){
						this.className='tabBg2-2';
					}else{
						this.className='tabBg1-1';
					}
				}else{
					if(this.id < id){
						this.className='tabBg1-1';
					}else if(this.id == id){
						this.className='tabBg1-2';
					}else{
						if(this.id=='5'){
							this.className ='tabBg2-3';
						}else{
							this.className ='tabBg1-3';
						}
					}
				}
			});
		},
		createTr : function($tbody, id,item,modelKey) {
			var _this = this;
			var calcheck = $('#calflag').val() == 0 ? false : true;
//			var difcheck = $('#difflag').val() == 0 ? false : true;
			var tr = document.createElement("tr");
//			var td_check = document.createElement("td");
			var td_carType = document.createElement("td");
			var td_chargeNo = document.createElement("td");
			var td_holiday = document.createElement("td");
			var td_working = document.createElement("td");
			var td_openGate = document.createElement("td");
			var td_mtcharge = document.createElement("td");
//			var checkbox = document.createElement("input");
//			checkbox.value = id;
//			checkbox.tabindex = -1;
//			checkbox.type = "checkbox";
//			checkbox.name = "charge_ids";
//			td_check.appendChild(checkbox);

			var carType = document.createElement("select");
			carType.name = "carType";
			carType.required = true;
			carType.setAttribute('data-validate','select');
			td_carType.appendChild(carType);
//			var defaultOption = document.createElement("option");
//			defaultOption.innerHTML = "";
//			carType.appendChild(defaultOption);
//			$(Utils.getModelArrayByParentModelKey(BASIS.VEHICLE_TYPE.ROOT)).each(function (inx, itm) {
			var itm = Utils.getDataDictByModelKey(modelKey);
			var option = document.createElement("option");
			option.innerHTML = itm.modelName;
			option.value = itm.modelValue;
//			if (item && item["carType"] == itm.modelValue) {
			option.setAttribute("selected", "selected")
//			}
			carType.appendChild(option);
//			});
			var chargeNo = document.createElement("select");
			chargeNo.name = "chargeNo";
			chargeNo.setAttribute('data-validate','select');
			td_chargeNo.appendChild(chargeNo);
			var defaultOption = document.createElement("option");
			defaultOption.innerHTML = "";
			chargeNo.appendChild(defaultOption);
			$(_this.tempchargeList).each(function (inx, itm) {
				var option = document.createElement("option");
				option.innerHTML = itm.name;
				option.value = itm.code;
				if (item && item["chargeNo"] == itm.code) {
					option.setAttribute("selected", "selected")
				}
				chargeNo.appendChild(option);
			});

			var holiday = document.createElement("select");
			holiday.name = "holiday";
			holiday.setAttribute('data-validate','select');
			td_holiday.appendChild(holiday);
			var defaultOption = document.createElement("option");
			defaultOption.innerHTML = "";
			holiday.appendChild(defaultOption);
			$(_this.tempchargeList).each(function (inx, itm) {
				var option = document.createElement("option");
				option.innerHTML = itm.name;
				option.value = itm.code;
				if (item && item["holiday"] == itm.code) {
					option.setAttribute("selected", "selected")
				}
				holiday.appendChild(option);
			});

			var working = document.createElement("select");
			working.name = "working";
			working.setAttribute('data-validate','select');
			td_working.appendChild(working);
			var defaultOption = document.createElement("option");
			defaultOption.innerHTML = "";
			working.appendChild(defaultOption);
			$(_this.tempchargeList).each(function (inx, itm) {
				var option = document.createElement("option");
				option.innerHTML = itm.name;
				option.value = itm.code;
				if (item && item["working"] == itm.code) {
					option.setAttribute("selected", "selected")
				}
				working.appendChild(option);
			});

			working.addEventListener('keydown', function(e) {
				if (e.keyCode == 9) {
					if ($(this).parents("tr").next().length < 1) {
						var $_no_input = $(this).parents("tr").find("select[name=carType]");
						var _val = $_no_input.val();
						if (_val == "" || _val == undefined || !_val) {
							e.returnValue = false;
							e.cancel = true;
							$_no_input.focus();
							return;
						}
						e.returnValue = false;
						e.cancel = true;
						new chargeBinfo(undefined, _this.targetObj.find("#charge_list")).addToList(_this);
						_this.targetObj.find("#charge_list tbody tr:last select[name=carType]").focus();
						return;
					}
				}
			});
			//创建开闸方式下拉列表  A闸 B闸
			var basisGate = Utils.getModelArrayByParentModelKey(BASIS.GATE_TYPE.ROOT);
			var openGate = $("<input style='width:99%' name='openGate'  required >");
			td_openGate.appendChild(openGate[0]);
			//创建月租收费标准

			/*var mtChargeSelect = $("<input style ='width:99%;' name= 'mtCharge' required>");
			var mtCharge = "";
			td_mtcharge.appendChild(mtChargeSelect[0]);
			JsonpAjax(baseApiPath + 'access_permission/charge_info/list', undefined, 'json', function(res) {
				mtChargeSelect.kendoDropDownList({
					dataTextField: "name",
					dataValueField: "code",
					dataSource: res
				}).data('kendoDropDownList');
			}, false);
			if(!isEmpty(item) && isNotEmpt(item["mtCharge"])){
				mtChargeSelect.data("kendoDropDownList").value(item["mtCharge"]);
			}else{
				mtChargeSelect.data("kendoDropDownList").select(0);
			}*/
            var mtCharge = document.createElement("select");
            mtCharge.name = "mtCharge";
            mtCharge.setAttribute('data-validate','select');
            td_mtcharge.appendChild(mtCharge);
            var defaultOption = document.createElement("option");
            defaultOption.innerHTML = "";
            mtCharge.appendChild(defaultOption);
            $(_this.monthchargeList).each(function (inx, itm) {
                var option = document.createElement("option");
                option.innerHTML = itm.name;
                option.value = itm.code;
                if (item && item["mtCharge"] == itm.code) {
                    option.setAttribute("selected", "selected")
                }
                mtCharge.appendChild(option);
            });
//			tr.appendChild(td_check);
			tr.appendChild(td_carType);
			tr.appendChild(td_chargeNo);
            tr.appendChild(td_holiday);
            tr.appendChild(td_working);
			tr.appendChild(td_mtcharge);
			tr.appendChild(td_openGate);
			$tbody[0].appendChild(tr);
			//初始化控件
			var that = this;  
			var kendoMultiSelect =  openGate.kendoMultiSelect({
				placeholder:"--请选择--",
				dataTextField:"modelName",
				dataValueField:"modelValue",
				dataSource:basisGate
			}).data("kendoMultiSelect");
			if (item && item["gateType"]) {
				kendoMultiSelect.value(item["gateType"].split(","));
			}
			_this.selectDisable(calcheck);

		},
		createTr2 : function($tbody, id,item,carTypes) {
			var _this = this;
			var tr = document.createElement("tr");
			var td_carType = document.createElement("td");
			var td_parkingNumber = document.createElement("td");
			var td_countFlag = document.createElement("td");
			var td_remainderFlag = document.createElement("td");
			var td_tempParking = document.createElement("td");


			var carType = document.createElement("select");
			carType.name = "carType";
			carType.required=true;
			td_carType.appendChild(carType);
			var defaultOption = document.createElement("option");
			/*defaultOption.innerHTML = "";
			carType.appendChild(defaultOption);*/

			$(carTypes).each(function (inx, itm) {
				if ((item && item["carType"] == itm.modelValue) || (!item && inx==id)) {
                    var option = document.createElement("option");
                    option.innerHTML = itm.modelName;
                    option.value = itm.modelValue;
                    option.setAttribute("selected", "selected");
                    carType.appendChild(option);
                }
			});


			var in_total = document.createElement("input");
			in_total.value = item == undefined ? '0' : item["countFlag"] == undefined ? '0' : item["countFlag"];
			in_total.checked = item == undefined ? false : item["countFlag"] == undefined ? false : item["countFlag"] == 0 ? false : true;
			in_total.type = "checkbox";
			in_total.name = "countFlag";
			in_total.onclick = function (e) {
				this.value= this.value !=1 ? 1 : 0;
			}
			td_countFlag.appendChild(in_total);

			var in_remainder = document.createElement("input");
			in_remainder.value = item == undefined ? '0' : item["remainderFlag"] == undefined ? '0' : item["remainderFlag"];
			in_remainder.checked = item == undefined ? false : item["remainderFlag"] == undefined ? false : item["remainderFlag"] == 0 ? false : true;
			in_remainder.type = "checkbox";
			in_remainder.name = "remainderFlag";
			in_remainder.onclick = function (e) {
				this.value= this.value !=1 ? 1 : 0;
			}
			td_remainderFlag.appendChild(in_remainder);

			var tempParking = document.createElement("input");
			tempParking.type = "text";
			tempParking.value = item == undefined ? '' : item["tempParking"] == undefined ? '' : item["tempParking"];
			tempParking.placeholder = "临时调整车位数量...";
			tempParking.name = "tempParking";
			tempParking.required = true;
			tempParking.setAttribute('data-validate','number');
			tempParking.setAttribute('validationMessage','临时调整车位必须是正负整数');
			tempParking.pattern = "^(0|[1-9][0-9]*|-[1-9][0-9]*)$";
			td_tempParking.appendChild(tempParking);

			var parkingNumber = document.createElement("input");
			parkingNumber.type = "text";
			parkingNumber.value = item == undefined ? '' : item["parkingNumber"] == undefined ? '' : item["parkingNumber"];
			parkingNumber.placeholder = "车位数量...";
			parkingNumber.name = "parkingNumber";
			parkingNumber.required = true;
			parkingNumber.setAttribute('data-validate','number');
			parkingNumber.setAttribute('validationMessage','车位数量必须是有效数字');
			parkingNumber.pattern = "^\\d+$";
			td_parkingNumber.appendChild(parkingNumber);



			tr.appendChild(td_carType);
			tr.appendChild(td_parkingNumber);
			tr.appendChild(td_countFlag);
			tr.appendChild(td_remainderFlag);
			tr.appendChild(td_tempParking);
			$tbody[0].appendChild(tr);
		},
    	createTr3 : function ($tbody, num,item) {
            var _this = this;
            var rowspan =1;
            if(!isEmpty(item.chn)){
                rowspan=item.chn.length;
            }
			if(rowspan==1){
                _this.createTr4($tbody,0,item,rowspan,true);
			}else if(rowspan>1){
                var init=false;
				for(var c=0;c<rowspan;c++){
					init = c==0?true:false;
                    _this.createTr4(_this.targetObj.find("#access_list > tbody"),c,item,rowspan,init,_this);
				}
			}

        },
    	createTr4:function ($tbody,num,item,rowspan,init,_this) {
    		if(item.chn.length <=0)return;
            var tr = document.createElement("tr");
			if(init){
                var td_wsnName = document.createElement("td");
                td_wsnName.rowSpan = rowspan;
                var wsnName = document.createElement("input");
                wsnName.value = item.organizationName;
                wsnName.type = "text";
                wsnName.name = "wsnName";
                wsnName.readOnly=true;
                td_wsnName.appendChild(wsnName);
			}


            var td_chnName = document.createElement("td");
            var td_repeat = document.createElement("td");
            var td_ck = document.createElement("td");
            var td_full = document.createElement("td");


           
            var chnName = document.createElement("input");
            chnName.value = item.chn[num].organizationName;
            chnName.type = "text";
            chnName.name = "chnName";
            chnName.alt=item.chn[num].organizationCode;
            chnName.readOnly=true;
            td_chnName.appendChild(chnName);

            //创建开闸方式下拉列表  A闸 B闸
            var repeat = Utils.getModelArrayByParentModelKey(BASIS.TRAFFIC_TYPE_CLASS.ROOT);
            var repeatGate = $("<input style='width:99%' name='repeatGate'  required >");
            td_repeat.appendChild(repeatGate[0]);

            var ck = Utils.getModelArrayByParentModelKey(BASIS.TRAFFIC_TYPE_CLASS.ROOT);
            var ckGate = $("<input style='width:99%' name='ckGate'  required >");
            td_ck.appendChild(ckGate[0]);

            var full = Utils.getModelArrayByParentModelKey(BASIS.TRAFFIC_TYPE_CLASS.ROOT);
            var fullGate = $("<input style='width:99%' name='fullGate'  required >");
            td_full.appendChild(fullGate[0]);
            if(init){
                tr.appendChild(td_wsnName);
            }
            tr.appendChild(td_chnName);
            tr.appendChild(td_repeat);
            tr.appendChild(td_ck);
            tr.appendChild(td_full);
            $tbody[0].appendChild(tr);

            //初始化控件
            var repeatSelect =  repeatGate.kendoMultiSelect({
                placeholder:"--请选择--",
                dataTextField:"modelName",
                dataValueField:"modelValue",
                dataSource:repeat,
            }).data("kendoMultiSelect");
            if (!isEmpty(item.chn)&&item.chn[num]['ckRepeatIE']) {
                repeatSelect.value(item.chn[num]['ckRepeatIE'].split(","));
            }

            var ckSelect =  ckGate.kendoMultiSelect({
                placeholder:"--请选择--",
                dataTextField:"modelName",
                dataValueField:"modelValue",
                dataSource:ck,
            }).data("kendoMultiSelect");
            if (!isEmpty(item.chn)&&item.chn[num]['ckIE']) {
                ckSelect.value(item.chn[num]['ckIE'].split(","));
            }
            var fullSelect =  fullGate.kendoMultiSelect({
                placeholder:"--请选择--",
                dataTextField:"modelName",
                dataValueField:"modelValue",
                dataSource:full
            }).data("kendoMultiSelect");
            if (!isEmpty(item.chn)&&item.chn[num]['fullStopIn']) {
                fullSelect.value(item.chn[num]['fullStopIn'].split(","));
            }
        },
		onChange:function () {
			var that=this;
            var name = that.element[0].name;
		},
		deleteRow : function(e) {
			var _this = this;
			if (!isEmpty(e)) {
				_this = $(e.target).data("that");
			}
			_this.targetObj.find("input[name=\"charge_ids\"]:checked").each(function(inx, itm) {
				$(itm).parents("tr").remove();
			});
		},
		createRow : function(e) {
			var _this = this;
			if (!isEmpty(e)) {
				_this = $(e.target).data("that");
				_this = null != _this ? _this : $(e.target).parent("a").data("that");
			}
			new chargeBinfo(undefined, _this.targetObj.find("#charge_list")).addToList(_this);
		},
		//保存收费标准信息
		saveparOrg:function(e){
			var that =  $(e.target).data("that");
			if(validityForm(that.targetObj)){
				var parkInfo = that.sysUtils.getBindDocJson();
				var url = baseApiPath+"facilities/saveParkInfo?isEdit=" + that.isEdit;
				var sendJson=parkInfo;
				for(var o in parkInfo){
					if(o.indexOf('_') !=-1){
						var strArray = o.substring(o.indexOf('_')+1);
						var name = o.substring(0, o.indexOf('_'));
						var jsonA = {};
						jsonA[name] = that.recursionObjectName(strArray,parkInfo[o]) ;
						delete parkInfo[o];
						var sendJson =$.extend(true,parkInfo,jsonA);
					}
				}
				var calcheck = $('#calflag').val() == 0 ? false : true;
//				var difcheck = $('#difflag').val() == 0 ? false : true;
				//封装收费规则数据
//				var boundTable = function (calcheck,difcheck) {

//				}
//				if(calcheck && difcheck || !calcheck && difcheck){
				delete sendJson['equipmentManagements']['charge']['workingDaysStandard'];
				delete sendJson['equipmentManagements']['charge']['holidaySeasonStandard'];
//				boundTable(calcheck,difcheck);
				var jsonD= {equipmentManagements:{charge:{chargelist:{}}}};
				var flagJsonD = false;
				that.targetObj.find("#charge_list > tbody tr").each(function (inx, itm) {
					var cols = $(itm).find("td");
					var carType = $(cols[0]).find("select").val();
					var chargeNo = $(cols[1]).find("select").val();
					var holiday = $(cols[2]).find("select").val();
					var working = $(cols[3]).find("select").val();
					var mtCharge = $(cols[4]).find("select[name='mtCharge']").val();
					var openGate = $(cols[5]).find("input[name='openGate']").data("kendoMultiSelect").value();
					if(null == openGate || openGate.length<=0){
						notification({ title:"提示信息",message:"请选择开闸方式!！"},'info');
						flagJsonD = true;
						return;
					}
					if(calcheck){
						jsonD.equipmentManagements.charge.chargelist["charge"+inx] = JSON.stringify({carType:carType,holiday:holiday,working:working,gateType:openGate.toString(),mtCharge:mtCharge});
					}else if(!calcheck){
						jsonD.equipmentManagements.charge.chargelist["charge"+inx] = JSON.stringify({carType:carType,chargeNo:chargeNo,gateType:openGate.toString(),mtCharge:mtCharge});
					}
				});

				//合并json对象
				sendJson = $.extend(true,sendJson,jsonD);
                //封装进出设置
				var jsonN = {accessList:[]};
                that.targetObj.find("#access_list > tbody tr").each(function (inx, itm) {
                    var cols = $(itm).find("td");
                    var i=0;
                    if($(cols[0]).find("input")[0].name=='wsnName'){
                        i=1;
					}
                    var chnCode = $(cols[i]).find("input").attr("alt");
                    var chnName = $(cols[i]).find("input").val();
                    var ckRepeatIE = $(cols[i+1]).find("input[name='repeatGate']").data("kendoMultiSelect").value();
                    var ckIE = $(cols[i+2]).find("input[name='ckGate']").data("kendoMultiSelect").value();
                    var fullStopIn = $(cols[i+3]).find("input[name='fullGate']").data("kendoMultiSelect").value();
//                    if(null == ckRepeatIE || ckRepeatIE.length<=0){
//                        notification({ title:"提示信息",message:"请选择"+chnName+"允许重复进出项!！"},'info');
//                        flagJsonD = true;
//                        return;
//                    }
//                    if(null == ckIE || ckIE.length<=0){
//                        notification({ title:"提示信息",message:"请选择"+chnName+"允许进出项!！"},'info');
//                        flagJsonD = true;
//                        return;
//                    }
//                    if(null == fullStopIn || fullStopIn.length<=0){
//                        notification({ title:"提示信息",message:"请选择"+chnName+"满位限入项!！"},'info');
//                        flagJsonD = true;
//                        return;
//                    }
                    jsonN.accessList.push(JSON.stringify({chnCode:chnCode,chnName:chnName,ckRepeatIE:ckRepeatIE.toString(),ckIE:ckIE.toString(),fullStopIn:fullStopIn.toString()}));
                });
                sendJson = $.extend(true,sendJson,jsonN);
                if(flagJsonD) return;

				/*var ckRepeatIEList = new Array(),ckIEList = new Array(),ckfullStopInList=new Array();
				that.targetObj.find("input[name='ckRepeatIE']:checked").each(function(){
					ckRepeatIEList.push($(this).data("modelValue"));
				});
				sendJson.equipmentManagements.charge["ckRepeatIE"] = ckRepeatIEList.toString();

				that.targetObj.find("input[name='ckIE']:checked").each(function(){
                    ckIEList.push($(this).data("modelValue"));
				});
				sendJson.equipmentManagements.charge["ckIE"] = ckIEList.toString();

                that.targetObj.find("input[name='ckfullStopIn']:checked").each(function(){
                    ckfullStopInList.push($(this).data("modelValue"));
                });
                sendJson.equipmentManagements.charge["fullStopIn"] = ckfullStopInList.toString();*/
//				}
//				else if(!calcheck && !difcheck){
//				delete sendJson['equipmentManagements']['charge']['holidaySeasonStandard'];
//				}

				//封装车位设置数据
//				var boundCarTypeArray = function () {
				var jsonE ={equipmentManagements:{carTypes:{}}};
				that.targetObj.find("#carType_list > tbody tr").each(function (inx, itm) {
					var cols = $(itm).find("td");
					var carType = $(cols[0]).find("select").val();
					var parkingNumber = $(cols[1]).find("input").val();
					var countFlag = $(cols[2]).find(":checkbox")[0].checked == false?0:1;
					var remainderFlag = $(cols[3]).find(":checkbox")[0].checked == false?0:1;
					var tempParking = $(cols[4]).find("input").val();
					if(carType && carType !=''){
						jsonE.equipmentManagements.carTypes["cartype"+inx] = JSON.stringify({carType:carType,parkingNumber:parkingNumber,countFlag:countFlag,remainderFlag:remainderFlag,tempParking:tempParking});
					}
				});
				//合并json对象
				sendJson = $.extend(true,sendJson,jsonE);

//				}
//				boundCarTypeArray();
				JsonpAjax(url,JSON.stringify(sendJson),"json",function(result){
                        that.sysUtils.setVariantBindFieldValue(result);
                    	that.isEdit=true;
                        parkTree.localUpdate(result);
				});
			}
		},
		recursionObjectName : function (strArray,val) {
			if (strArray.indexOf('_') == -1){
				var jsonC = {};
				jsonC[strArray]=val;
				return jsonC;
			}
			var name = strArray.substring(0, strArray.indexOf('_'));
			strArray = strArray.substring(strArray.indexOf('_')+1);
			var jsonB = {};
			jsonB[name] = this.recursionObjectName(strArray,val);
			return jsonB;
		}
}
